package com.sinoglobal.ningxia.qr;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.sinoglobal.ningxia.R;
import com.sinoglobal.ningxia.frame.ShareAbstractActivity;
import com.sinoglobal.ningxia.http.ConnectionUtil;
import com.sinoglobal.ningxia.utils.TextUtil;
import com.sinoglobal.ningxia.utils.ValidUtil;

/**
 * @author limeishu
 * @createdate 2014-9-4 下午4:59:47
 * @Description: 展示扫描文本信息结果页面
 */
public class QrStrResultActivity extends ShareAbstractActivity {
    private TextView result;
    private TextView copy;// 复制文本信息
    private TextView share;// 分享
    private TextView visitUrl;// 访问网址
    private String resultStr;

    @SuppressLint("NewApi")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_qr_str_result);
        openChenJInShi();//开启沉浸式
        resultStr = getIntent().getStringExtra("captureResult");
        mActivity = this;
        init();
        // 判断是网址信息或者文本信息
        if (TextUtil.stringIsNull(ValidUtil.validUrl(resultStr))) {
            titleView.setText(getString(R.string.qr_history_url));
            visitUrl.setVisibility(View.VISIBLE);

        } else {
            titleView.setText(getString(R.string.qr_history_text));
            visitUrl.setVisibility(View.GONE);
            copy.setTop(20);
            copy.setBackgroundResource(R.drawable.btn_selector);
            copy.setTextColor(getResources().getColor(R.color.white));
        }
        setOnClick();
    }

    private void setOnClick() {
        // 点击复制到剪切板
        copy.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                TextUtil.copy(resultStr, getApplicationContext());
                showShortToastMessage(getString(R.string.qr_text_copy_success));
            }
        });
        // 点击分享
        share.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                showPopwindow(true, getIntent().getStringExtra("captureResult") + getString(R.string.share_postfix) + ConnectionUtil.MicDoorAdress, null,
                        ConnectionUtil.MicDoorAdress);

            }
        });
        // 点击访问网页
        visitUrl.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getApplicationContext(),
                        QrUrlResultActivity.class);
                intent.putExtra("captureResult", resultStr);
                startActivity(intent);
            }
        });
    }

    private void init() {
        result = (TextView) findViewById(R.id.result_content);
        copy = (TextView) findViewById(R.id.copy_text_btn);
        share = (TextView) findViewById(R.id.share_btn);
        visitUrl = (TextView) findViewById(R.id.visit_url_btn);
        result.setText(resultStr);
    }
}
